/*
 * =====================================================================================
 *
 *       Filename:  mcuserver.h
 *
 *    Description:  Main server enterpoint.
 *
 *        Version:  1.0
 *        Created:  04/16/2015 10:27:04 AM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Dellinger.Zhang (mn), rainxy2000@hotmail.com
 *        Company:  Hujiang.com
 *
 * =====================================================================================
 */

#ifndef __MCUSERVER_H__
#define __MCUSERVER_H__

#include "ctSubNetService.h"
#include "ctTCPTaskPool.h"
#include "ctType.h"
#include "ctSingleton.h"
#include "command.h"
#include "def.h"
#include <stdint.h>

class MCUServer : public ctSubNetService,
	              public Singleton<MCUServer>
{
	friend class Singleton<MCUServer>;

	public:
		const int size() const
		{
			if (pool_)
			{
				return pool_->getSize();
			}
			return 0;
		}
		const int state() const
		{
			return pool_->getState();
		}

	public:
		bool msgParse_SuperService(const Cmd::t_NullCmd* pNullCmd, const DWORD nCmdLen);
		bool msgParse_MediaRecord(const Cmd::t_NullCmd* cmd, const DWORD cmdlen);
		void notifySuperRecordingState(uint32_t record_id, uint8_t state) 
		{
			Zebra::logger->debug("%s", __PRETTY_FUNCTION__);
		}
		void errorReport(uint32_t record_id, const std::string& error_msg) 
		{
			Zebra::logger->debug("%s", __PRETTY_FUNCTION__);
		}

	private:
		MCUServer() : ctSubNetService("MCUServer", MCU_SERVER_TYPE)
		{
			pool_ = NULL;
		}
		virtual ~MCUServer() 
		{
			if (pool_)
			{
				pool_->final();
				SAFE_DELETE(pool_);
			}
		}
		void newTCPTask(const int sock, const struct sockaddr_in* addr);
		bool init();
		void final() {};
		virtual bool validate()
		{
			return ctSubNetService::validate();
		}

	private:
		ctTCPTaskPool*	pool_;

};

#define theserver MCUServer::getSingleton()

#endif //__MCUSERVER_H__

